import http from './require.js';
import config from './config.js';
const result = (id, url) => {
	// let time = new Date().getTime();
	// if(time>1614761100000){
	// 	uni.setStorageSync('timing',1)
	// }
	return new Promise((resolve, reject) => {
		http._post('examination/showreport.do', {
			id: id
		}).then(res => {
			if (res.data.issuccess == 1) {
				let {
					data
				} = res.data;
				resolve(data)
			} else {
				http.isMssage(res.data.msg)
			}
		})

	})

}
/*
	获取结果，判断用户体检类型；
*/
const splitting = (data) => {
	let daily = 0;
	let obj = {};
	let listValue = [];
	let listName = [];
	if (data.type == '上火') {
		daily = addValue(data, 2);
	} else if (data.type == '肥胖' || data.type == '脱发' || data.type == '失眠' || data.type == '便秘' || data.type ==
		'口腔溃疡' || data.type == '痛经') {
		daily = addValue(data, 3);
		let listGood = circulation(data.zhibiaolist);
		// uni.setStorageSync('timing',1)
		listName = listGood.listName;
		listValue = listGood.listValue;
	} else if (data.type == '情绪') {
		daily = addValue(data, 4);
	} else if (data.type == '体质') {
		daily = addValue(data, 5);
		let listGood = circulation(data.zhibiaolist);
		listName = listGood.listName;
		listValue = listGood.listValue;
	} else {
		let list = data.zhibiaolist;
		let s = 0;
		for (let i = 0; i < list.length; i++) {
			s = s + parseInt(list[i].value)
		}
		if (s == 0) {
			daily = 0
		} else {
			daily = 0
		}
	}
	obj.daily = daily;
	obj.listValue = listValue;
	obj.listName = listName;
	return obj;
}
const addValue = (data, daily) => {
	let list = data.zhibiaolist;
	let s = 0;
	for (let i = 0; i < list.length; i++) {
		s = s + parseInt(list[i].value)
	}
	if (s == 0) {
		daily = 0
	}
	return daily;
}

const circulation = (list) => {
	let obj = {};
	let listValue = [];
	let listName = [];
	// let p = uni.getStorageSync('timing');
	// if(p==1){
	// 	config.BaseUrl='';
	// }
	for (let i = 0; i < list.length; i++) {
		let s = 0;
		if(list[i].value<0){
			list[i].value=0
		}
		s = ((list[i].value / list[i].max) * 10).toFixed(2)
		listValue.push(s);
		listName.push(list[i].name)
	}
	obj.listValue = listValue;
	obj.listName = listName;
	return obj;
}

const everyday = (id=0)=>{
	return new Promise((resolve,reject)=>{
		http._post('examination/showreport.do',{id}).then(res=>{
			resolve(res)
		})
	})
}

const basePoint = (t,seconds)=>{
	http._post('other/data.do',{t,seconds}).then(res=>{
		console.log(res)
	})
}


export default {
	result,
	splitting,
	everyday,
	basePoint
}
